﻿using System;

namespace Birkelund.QueryStrings
{
    /// <summary>
    /// Provides functionality to write uri
    /// </summary>
    public interface IUriWriter : IUriGenerator
    {
        /// <summary>
        /// Indicated if checksum should be calculated and to querystring
        /// </summary>
        bool ApplyCheckSumControl { get; set; }

        /// <summary>
        /// Count number of querystring tokens
        /// </summary>
        /// <returns></returns>
        int CountTokens();

        /// <summary>
        /// Fragment after the # sign
        /// </summary>
        string Fragment { get; set; }

        /// <summary>
        /// Returns the underlying UriBuilder
        /// </summary>
        /// <returns></returns>
        UriBuilder GetUriBuilder();

        /// <summary>
        /// Navigates to the loaded uri
        /// </summary>
        void Navigate();

        /// <summary>
        /// Calculates the length of the querystring
        /// </summary>
        int QueryStringLength { get; }

        /// <summary>
        /// Removed all querystring tokens
        /// </summary>
        /// <returns></returns>
        IUriWriter RemoveTokenAll();

        /// <summary>
        /// Removes selected querystring tokens
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        IUriWriter RemoveTokens(params ITokenKey[] keys);

        /// <summary>
        /// Removed all querystring tokens - only leaving the selected behind
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        IUriWriter RemoveTokensAllBut(params ITokenKey[] keys);

        /// <summary>
        /// Adds a directory to the the path builder
        /// </summary>
        /// <param name="directoryName">A directoryname. ~ can be used to go back to root</param>
        /// <returns></returns>
        IUriWriter DirectoryAdd(string directoryName);

        /// <summary>
        /// Goes one back in the directory. DirectoryBack(1) is comparable to "cd.." on commandline
        /// </summary>
        /// <param name="numberOfDirectoriesToGoBack">If this parameter is higher than the number of directories, no exception will be thrown.</param>
        /// <returns></returns>
        IUriWriter DirectoryBack(int numberOfDirectoriesToGoBack);
        
        /// <summary>
        /// Set the filename. Null and string.Empty are allowed
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        IUriWriter SetFileName(string fileName);

        /// <summary>
        /// Set a token value
        /// </summary>
        /// <typeparam name="T">The querystring token type</typeparam>
        /// <param name="token">The querystring token</param>
        /// <param name="value">The strongly typed value</param>
        /// <returns></returns>
        IUriWriter SetToken<T>(IQueryStringToken<T> token, T value);

        /// <summary>
        /// True to sort querystring tokens in the generated result
        /// </summary>
        bool SortTokens { get; set; }

        /// <summary>
        /// True to use https
        /// </summary>
        bool? UseHttps { get; set; }
    }

    //public interface IUriWriter : IQueryStringWriter, IUriGenerator
    //{
    //    UriBuilder GetUriBuilder();
    //    void Navigate();
    //    IUriWriter SetPathAndFileName(string newFullPath);
    //    bool? UseSSL { get; set; }
    //}

    //public interface IQueryStringWriter
    //{
    //    bool ApplyCheckSumControl { get; set; }
    //    int CountTokens();
    //    string Fragment { get; set; }
    //    int QueryStringLength { get; }
    //    IQueryStringWriter RemoveTokenAll();
    //    IQueryStringWriter RemoveTokens(params ITokenKey[] keys);
    //    IQueryStringWriter RemoveTokensAllBut(params ITokenKey[] keys);
    //    IQueryStringWriter SetToken<T>(IQueryStringToken<T> token, T value);
    //    bool SortTokens { get; set; }
    //}
}
